package com.zjc.app.api.sdk.dto.result;

import java.util.Date;
import java.util.List;

/**
 * 指令发送结果
 */
public class ApiCommandResultDTO {

    /**
     * 所有指令是否已获取到结果
     */
    private Boolean completed;
    /**
     * 指令结果集
     */
    private List<SingleCommandResult> results;

    public Boolean getCompleted() {
        return completed;
    }

    public void setCompleted(Boolean completed) {
        this.completed = completed;
    }

    public List<SingleCommandResult> getResults() {
        return results;
    }

    public void setResults(List<SingleCommandResult> results) {
        this.results = results;
    }

    public static class SingleCommandResult {
        /**
         * 成功code
         */
        public static final String SUCCESS_CODE = "1000";
        /**
         * 回复结果
         */
        private String result;
        /**
         * 回复结果描述
         */
        private String resultDesc;
        /**
         * 回复时间
         */
        private Date time;

        public String getResult() {
            return result;
        }

        public void setResult(String result) {
            this.result = result;
        }

        public String getResultDesc() {
            return resultDesc;
        }

        public void setResultDesc(String resultDesc) {
            this.resultDesc = resultDesc;
        }

        public Date getTime() {
            return time;
        }

        public void setTime(Date time) {
            this.time = time;
        }

        /**
         * 是否成功
         * @return 是否成功
         */
        public boolean isSuccess() {
            return SUCCESS_CODE.equals(result);
        }
    }

    /**
     * 是否全部成功
     * @return 是否全部成功
     */
    public boolean isAllSuccess() {
        if (!completed) {
            return false;
        }
        if (results != null && results.size() > 0) {
            for (SingleCommandResult result : results) {
                if (!result.isSuccess()) {
                    return false;
                }
            }
        }
        return true;
    }
}
